﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MyLib;
namespace WebPortal
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        string str = "";
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strWhere = "";
            if (TextBox1.Text.Trim() != "")
            {
                strWhere += " AND  firstname like '%" + TextBox1.Text + "%' ";
            }
            if (TextBox2.Text.Trim() != "")
            {
                strWhere += " AND  A.Employeeid = '" + TextBox2.Text + "' ";
            }
            DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable("select * from V_EMPLOYEE A inner join  V_EMPDEPARTMENTS B on a.EmployeeID = b.EmployeeID inner join  V_DEPARTMENT C ON B.DepartmentID = C.DepartmentID   where 1=1 " + strWhere + " ");
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    str += row["firstname"].ToString() + "[" + row["EmployeeID"].ToString() + "]>>" + row["DepartmentName"].ToString();
                    string ParentID = row["ParentID"].ToString();
                    GetV_DEPARTMENT(ParentID);
                }
                divMsg.InnerHtml = str;
            }
            else
            {
                divMsg.InnerHtml = "未查询到结果！";
            }

        }
        private void GetV_DEPARTMENT(string ParentID)
        {
            if (ParentID != "0")
            {
                DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable(string.Format("select * from {0} where DepartmentID='{1}'", "V_DEPARTMENT", ParentID));
                if (dt.Rows.Count > 0)
                {
                    str += ">>" + dt.Rows[0]["DepartmentName"].ToString();
                    GetV_DEPARTMENT(dt.Rows[0]["ParentID"].ToString());
                }
            }
            else
            {
                str += "<hr/>";
            }

        }

        protected void btn1_Click(object sender, EventArgs e)
        {
            //CustomOC.OCSync oc = new CustomOC.OCSync();
            //object oUser, Obj1, obj2, obj3;

            ////oc.GetDepartmentMembersFromName("集团本部[1018501]", out oUser, out Obj1, out obj3, out obj2);
            ////oUser = oc.GetGroupMembers("服务业务单元");
            //oc.GetUserGroups("ULTIMUS/1588", out oUser);
            //if (oUser != null)
            //{
            //    lst.DataSource = oUser as string[];
            //    lst.DataBind();
            //    //ListBox1.DataSource = Obj1 as string[];
            //    //ListBox2.DataSource = obj2 as string[];
            //    //ListBox1.DataBind(); ListBox2.DataBind();
            //}

            //CustomOC.OCSync oc = new CustomOC.OCSync();
            //object oUser,Obj1,obj2,obj3;

            //oc.GetDepartmentMembersFromName("集团本部[1018501]", out oUser, out Obj1, out obj3, out obj2);
        }

        protected void Check_Click(object sender, EventArgs e)
        {
            //Ultimus.UltLibGW ult = new Ultimus.UltLibGW();
            ProcessControl.Logic.ApprovalHistoryLogic al = new ProcessControl.Logic.ApprovalHistoryLogic();
            string strError = "";
            string strFinanc = "";
            string strCashier = "";
            // ult.GetFinancePerson(txtProcess.Text, txtCompany.Text, txtCenterDept.Text, txtDept.Text, out strError, ref strFinanc, ref strCashier);
            al.GetFinancePerson(txtProcess.Text, txtCompany.Text, txtCenterDept.Text, txtDept.Text, ref strFinanc, ref strCashier);
            this.lbMsg.Text = strError;
            this.lbFinance.Text = strFinanc;
            this.lbCashier.Text = strCashier;
        }
    }
}